if (size_increase > 0) {
qba.append(size_increase, 0);
}
- qba.replace(index, count, (char*) data, count);
+ qba.replace(index, count, static_cast<const char*>(data), count);
tag->data[0] = qba;
} else {
// we haven't coded for insertion of multiple values (except for BYTE_TYPE above).
case EXIF_TYPE_SHORT:
case EXIF_TYPE_SSHORT:
tag->grow<uint16_t>(index + count);
- tag->data[index] = *(uint16_t*)data;
+ tag->data[index] = *static_cast<const uint16_t*>(data);
break;
case EXIF_TYPE_LONG:
case EXIF_TYPE_SLONG:
case EXIF_TYPE_IFD:
tag->grow<uint32_t>(index + count);
- tag->data[index] = *(uint32_t*)data;
+ tag->data[index] = *static_cast<const uint32_t*>(data);
break;
case EXIF_TYPE_RAT:
case EXIF_TYPE_SRAT: {
- double val = *(double*)data;
+ double val = *static_cast<const double*>(data);
if ((val < 0.0) && (type == EXIF_TYPE_RAT)) {
fatal(MYNAME ": A negative value cannot be stored as type RATIONAL.");
break;
case EXIF_TYPE_FLOAT:
tag->grow<float>(index + count);
- tag->data[index] = *(float*)data;
+ tag->data[index] = *static_cast<const float*>(data);
break;
case EXIF_TYPE_DOUBLE:
tag->grow<double>(index + count);
- tag->data[index] = *(double*)data;
+ tag->data[index] = *static_cast<const double*>(data);
break;
default:
fatal(MYNAME ": Unknown data type %u!\n", type);
prevPt = thisPt;
}
}
- auto* dptr = (double*)(&cachedLength); // big cheat
- *dptr = dist;
+ *const_cast<double*>(&cachedLength) = dist; // big cheat
return cachedLength;
}
}
}
}
- auto* dptr = (double*)(&cachedLength); // big cheat
- *dptr = dist;
+ *const_cast<double*>(&cachedLength) = dist; // big cheat
return cachedLength;
}
int
gusb_cmd_send(const garmin_usb_packet* opkt, size_t sz)
{
- auto* obuf = (unsigned char*) &opkt->dbuf;
+ const auto* obuf = opkt->dbuf;
const char* m2;
unsigned int rv = gusb_llops->llop_send(opkt, sz);
garmin_usb_packet iresp;
int i;
- gusb_cmd_send((garmin_usb_packet*)oid, sizeof(oid));
+ gusb_cmd_send(reinterpret_cast<const garmin_usb_packet*>(oid), sizeof(oid));
for (i = 0; i < 25; i++) {
iresp.gusb_pkt.type = 0;
gusb_win_send(const garmin_usb_packet* opkt, size_t sz)
{
DWORD rsz;
- unsigned char* obuf = (unsigned char*) &opkt->dbuf;
+ const auto* obuf = opkt->dbuf;
/* The spec warns us about making writes an exact multiple
* of the packet size, but isn't clear whether we can issue
}
}
- hdevinfo = SetupDiGetClassDevs((GUID*) &GARMIN_GUID, NULL, NULL,
+ hdevinfo = SetupDiGetClassDevs(&GARMIN_GUID, NULL, NULL,
DIGCF_PRESENT | DIGCF_INTERFACEDEVICE);
if (hdevinfo == INVALID_HANDLE_VALUE) {
if (req_unit_number >= 0) {
if (!SetupDiEnumDeviceInterfaces(hdevinfo, NULL,
- (GUID*) &GARMIN_GUID,
+ &GARMIN_GUID,
req_unit_number, &devinterface)) {
// If there were zero matches, we may be trying to talk to a "GPX Mode" device.
*/
for (match = 0;; match++) {
if (!SetupDiEnumDeviceInterfaces(hdevinfo, NULL,
- (GUID*) &GARMIN_GUID, match, &devinterface)) {
+ &GARMIN_GUID, match, &devinterface)) {
if (GetLastError() == ERROR_NO_MORE_ITEMS) {
break;
void GPS_Util_Put_Short(UC* s, const US v)
{
- UC* p;
-
- p = (UC*)&v;
+ const auto* p = reinterpret_cast<const UC*>(&v);
if (!GPS_Little) {
*s++ = *(p+1);
void GPS_Util_Put_Double(UC* s, const double v)
{
- UC* p;
int32 i;
- p = (UC*)&v;
+ const auto* p = reinterpret_cast<const UC*>(&v);
if (!GPS_Little)
for (i=sizeof(double)-1; i>-1; --i) {
void GPS_Util_Put_Int(UC* s, const int32 v)
{
- UC* p;
int32 i;
- p = (UC*)&v;
+ const auto* p = reinterpret_cast<const UC*>(&v);
if (!GPS_Little)
for (i=sizeof(int32)-1; i>-1; --i) {
void GPS_Util_Put_Uint(UC* s, const uint32 v)
{
- UC* p;
int32 i;
- p = (UC*)&v;
+ const auto* p = reinterpret_cast<const UC*>(&v);
if (!GPS_Little)
for (i=sizeof(uint32)-1; i>-1; --i) {
void GPS_Util_Put_Float(UC* s, const float v)
{
- UC* p;
int32 i;
- p = (UC*)&v;
+ const auto* p = reinterpret_cast<const UC*>(&v);
if (!GPS_Little)
for (i=sizeof(float)-1; i>-1; --i) {
auto* waypt = new Waypoint;
decode_position(buffer + 12, waypt);
- waypt->shortname = (char*) buffer + 4;
+ waypt->shortname = reinterpret_cast<const char*>(buffer) + 4;
waypt->icon_descr = icon_table[buffer[28]];
waypt->SetCreationTime(decode_datetime(buffer + 22));
int plen, ilen;
for (plen = 0; plen < len && buf[plen] != 0xFF; plen += ilen) {
- ilen = process_data_item(pst, (item_frame*)&buf[plen], len-plen);
+ ilen = process_data_item(pst, reinterpret_cast<const item_frame*>(&buf[plen]), len-plen);
if (ilen <= 0) {
fatal(MYNAME ": Error %i while processing data item #%i (starts at %i)\n",
ilen, pst->tpn, plen);
p = ptr;
} else {
for (int i = 0; i < 8; i++) {
- r[i] = ((char*)ptr)[7-i];
+ r[i] = static_cast<const char*>(ptr)[7-i];
}
p = r;
}
p = ptr;
} else {
for (int i = 0; i < 4; i++) {
- r[i] = ((char*)ptr)[3-i];
+ r[i] = static_cast<const char*>(ptr)[3-i];
}
p = r;
}
get_crc32(const void* data, int datalen)
{
unsigned long crc = 0xFFFFFFFF;
- const unsigned char* cp = (unsigned char*)data;
+ const unsigned char* cp = static_cast<const unsigned char*>(data);
- while (cp < ((unsigned char*)data + datalen)) {
+ while (cp < (static_cast<const unsigned char*>(data) + datalen)) {
crc = ((crc >> 8) & 0x00FFFFFF) ^ crc32_table[(crc ^ *cp) &0xFF];
cp++;
}
static void buf_update_checksum(struct buf_head* h, const void* data, size_t len)
{
- auto* cp = (unsigned char*) data;
+ auto* cp = static_cast<const unsigned char*>(data);
db(4, "Updating checksum with %p, %zu, before: %02x ",
data, len, h->checksum);